﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
namespace Ecreate.Web.utility
{
    public class Javascript
    {
        public static string BuildJavaScript(System.Web.UI.Page page, string Script)
        {
            StringBuilder sbuilder = new StringBuilder();
            sbuilder.Append("<script type=\"text/javascript\" language=\"javascript\">   ");
            sbuilder.Append(Script);
            sbuilder.Append(@"</script>  ");
            return sbuilder.ToString();

        }
        public static void InjectScript(System.Web.UI.Page page, string Script)
        {
            string javascript = BuildJavaScript(page, Script);
            page.ClientScript.RegisterStartupScript(page.GetType(), "", javascript);
        }

        public static void InjectMessageScript(System.Web.UI.Page page, string Message)
        {
            string messageScript = BuildAlertScript(Message);
            string javascript = BuildJavaScript(page, messageScript);
            page.ClientScript.RegisterStartupScript(page.GetType(), "", javascript);
        }

        private static string BuildAlertScript(string Message)
        {
            return " alert ('" + Message + "') ;";
        }
    }
}
